package com.rest.demo.functional;

import org.apache.commons.lang.math.RandomUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author Administrator
 * @decription
 * @Date 2018-01-29 9:46
 */
public class FunctionInterfaceDemo {

    public static void main(String[] args) {
//        boolean isAdult = doPredicate(20, x -> x >= 18);
//        System.out.println(isAdult);
//        donation(10,money -> System.out.println("钱:"+money+"元"));
//
//        List<Integer> list = supply(10,() -> RandomUtils.nextInt(100));
//
//        list.stream().forEach(System.out::println);

        Integer result = convert("128",str -> Integer.valueOf(str));
        System.out.println(result);
    }

    public static boolean doPredicate(int age, Predicate<Integer> predicate) {
        return predicate.test(age);
    }

    public static void donation(int money, Consumer<Integer> consumer) {
        consumer.accept(money);
    }

    public static List<Integer> supply(Integer num, Supplier<Integer> supplier) {
        List<Integer> resultList = new ArrayList<Integer>();
        for (int i = 0; i < num; i++) {
            resultList.add(supplier.get());
        }
        return resultList;
    }

    public static Integer convert(String str, Function<String,Integer> function) {
       return function.apply(str);
    }
}
